-- Insert a string into another string at a specified position

function insert (orig_str, pos, insert_str)
	if pos == 0 or pos > #orig_str then
		return nil
	elseif pos == 1 then
		return (insert_str .. orig_str)
	elseif pos == -1 or pos == #orig_str then
		return (orig_str .. insert_str)
	else
		first_part = string.sub(orig_str, 1, pos - 1)
		second_part = string.sub(orig_str, pos, -1)
		return (first_part .. insert_str .. second_part)
	end
end

-- test
print(insert("hello world", 1, "start: "))
print(insert("hello world", 7, "small "))
